/**
 * @author fenglei.you
 */
Me.Util={};
Me.Util.propertySet=function(options){
	if(options){
		this.x=options.x;
		this.y=options.y;
		this.width=options.width;
		this.height=options.height;
		
		if(options.bgImage){
			var img = new Image();
			img.src = options.bgImage;
			
			this.imgObj={};
			this.imgObj.img=img;
			this.imgObj.x=options.bgImageX;
			this.imgObj.y=options.bgImageY;
			this.imgObj.w=options.bgImageW;
			this.imgObj.h=options.bgImageH;			
		}
		
		this.parent = options.parent;	
		if(this.parent){
			this.display = new Me.Display(this.x+this.parent.x,this.y+this.parent.y,this.width,this.height);		
		}else{
			this.display = new Me.Display(this.x,this.y,this.width,this.height);	
		}
	}
}

Me.Util.paint=function(context){	
	if(this.parent){
		context.drawImage(this.imgObj.img,this.imgObj.x,this.imgObj.y,this.imgObj.w,this.imgObj.h,
			this.parent.x+this.x,this.parent.y+this.y,this.width,this.height);
	}else{
		context.drawImage(this.imgObj.img,this.imgObj.x,this.imgObj.y,this.imgObj.w,this.imgObj.h,
			this.x,this.y,this.width,this.height);	
	}
	
	var childs = this.childs;
	if(childs){
		for(var index=0;index<childs.length;index++){
			var current = childs[index];
			Me.Util.paint.apply(current,arguments);
			if(current.customePaint){
				current.customePaint(context);
			}
		}
	}
	
}
Me.Util.clear=function(context){
	this.display.clear(context);
}
Me.Util.mesureText=function(holder,text,align,context){
	var pos={};
	pos.y = holder.y+holder.height/2;
	
	if(align=='left'){
		pos.x= holder.x;		
	}else if(align=='right'){
		var mesureLen = context.measureText(text).width;
		pos.x = holder.x+ Math.max(0,holder.width-mesureLen);		
	}else{
		var mesureLen = context.measureText(text).width;
		pos.x = holder.x+ Math.max(0,(holder.width-mesureLen)/2);		
	}
	return pos;
}
